//
//  UserDefaults.m
//  bijaking
//
//  Created by Ourpower on 2014/9/24.
//  Copyright (c) 2014年 Ourpower. All rights reserved.
//

#import "UserDefaults.h"

@implementation UserDefaults

+ (NSUserDefaults *) sharedInstance {
    return [NSUserDefaults standardUserDefaults];
}

+ (BOOL) set: (id) value withKey: (NSString *) key {
    if ( key && value ) {
        NSUserDefaults *userDefaults = [self sharedInstance];
        [userDefaults setObject: value forKey: key];
        
        return [userDefaults synchronize];
    }
    return NO;
}

+ (id) get: (NSString *) key {
    if ( key ) {
        return [[self sharedInstance] objectForKey: key];
    }
    return nil;
}

+ (void) remove: (NSString *) key {
    if ( key ) {
        [[self sharedInstance] removeObjectForKey: key];
    }
}

+ (BOOL) setArchiver: (id) myObject withKey: (NSString *) key {
    return [self set: [NSKeyedArchiver archivedDataWithRootObject: myObject] withKey: key];
}

+ (id) getArchiver: (NSString *) key {
    if ( key ) {
        return [NSKeyedUnarchiver unarchiveObjectWithData: (NSData *)[self get: key]];
    }
    return nil;
}
@end
